package com.itsq.controller.resources;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itsq.common.base.BaseController;
import com.itsq.common.bean.ErrorEnum;
import com.itsq.common.bean.Response;
import com.itsq.pojo.dto.PageDepartmentDto;
import com.itsq.pojo.dto.PageUsagerecordDto;
import com.itsq.pojo.dto.UsageRecordEndDto;
import com.itsq.pojo.entity.Department;
import com.itsq.pojo.entity.UsageRecord;
import com.itsq.service.resources.DepartmentService;
import com.itsq.service.resources.UsageRecordService;
import com.itsq.token.CurrentUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 史先帅
 * @since 2021-01-30
 */
@RestController
@RequestMapping("/usageRecord")
@AllArgsConstructor
@CrossOrigin
@Api(tags = "使用记录信息模块")
public class UsageRecordController  extends BaseController {

    @Autowired
    private UsageRecordService usageRecordService;

    @PostMapping("selUsageRecordPageFront")
    @ApiOperation(value = "使用记录信息模块前台分页查询", notes = "", httpMethod = "POST")
    public Response<Page<UsageRecord>> selUsageRecordPageFront(@RequestBody PageUsagerecordDto pageUsagerecordDto){
        Page<UsageRecord> UsageRecordPage = usageRecordService.selUsageRecordPageFront(pageUsagerecordDto);
        return Response.success(UsageRecordPage);
    }

    @PostMapping("selUsageRecordPageAfter")
    @ApiOperation(value = "管理员——使用记录信息模块后台分页查询", notes = "", httpMethod = "POST")
    public Response<Page<UsageRecord>> selUsageRecordPageAfter(@RequestBody PageUsagerecordDto pageUsagerecordDto){
        CurrentUser currentUser = currentUser();
        if(currentUser==null){
            return Response.fail(ErrorEnum.SIGN_VERIFI_EXPIRE);
        }
        Page<UsageRecord> UsageRecordPage = usageRecordService.selUsageRecordPageAfter(pageUsagerecordDto);
        return Response.success(UsageRecordPage);
    }

    @PostMapping("selUsageRecordById")
    @ApiOperation(value = "管理员——使用记录信息模块用户查询记录", notes = "", httpMethod = "POST")
    public Response<Page<UsageRecord>> selUsageRecordById(@RequestBody PageUsagerecordDto pageUsagerecordDto){
        Page<UsageRecord> UsageRecordPage = usageRecordService.selUsageRecordById(pageUsagerecordDto);
        return Response.success(UsageRecordPage);
    }

    @PostMapping("insertBegin")
    @ApiOperation(value = "使用记录信息模块添加", notes = "", httpMethod = "POST")
    public Response<UsageRecord> insert(@RequestBody UsageRecord usageRecord){
//        CurrentUser currentUser = currentUser();
//        if(currentUser==null){
//            return Response.fail(ErrorEnum.SIGN_VERIFI_EXPIRE);
//        }
        return Response.success(usageRecordService.insertBegin(usageRecord));
    }

    @PostMapping("updateEnd")
    @ApiOperation(value = "使用记录信息模块结束", notes = "", httpMethod = "POST")
    public Response<Integer> updateEnd(@RequestBody UsageRecordEndDto usageRecordEndDto){
//        CurrentUser currentUser = currentUser();
//        if(currentUser==null){
//            return Response.fail(ErrorEnum.SIGN_VERIFI_EXPIRE);
//        }
        return Response.success(usageRecordService.updateEnd(usageRecordEndDto));
    }

    @PostMapping("update")
    @ApiOperation(value = "使用记录信息模块修改", notes = "", httpMethod = "POST")
    public Response<Integer> update(@RequestBody UsageRecord usageRecord){
        return Response.success(usageRecordService.update(usageRecord));
    }

    @PostMapping("selUsageRecordStatus")
    @ApiOperation(value = "使用记录信息模块查询汽车使用状态", notes = "", httpMethod = "POST")
    public Response<List<UsageRecord>> selUsageRecordStatus(@RequestBody UsageRecord usageRecord){
        return Response.success(usageRecordService.selUsageRecordStatus(usageRecord));
    }

    @PostMapping("status")
    @ApiOperation(value = "使用记录信息模块查询当前用户是否使用汽车", notes = "", httpMethod = "POST")
    public Integer status(@RequestBody UsageRecord usageRecord){
        return usageRecordService.status(usageRecord);
    }
}

